import React from 'react'
import { Route, Redirect, withRouter } from 'react-router-dom'

//1.登陆权限
//2.登陆后的页面权限
class AuthRoute extends React.Component {
    render() {
        const { component: Component, render, ...rest } = this.props
        //token存在的表象
        let isLogged = (localStorage.getItem("token") || '').length > 0;

        isLogged = true;

        if (!isLogged) {
            //给个提示，延时跳转登陆页
            // message.error('需要登陆权限,正在跳转登陆页...');
            setTimeout(() => {
                window.location.href = "login.html"
            }, 1500);

            // var that = this;
            // that.props.history.push('/login');

        }
        return (
            <Route {...rest} render={props => {
                // return <ErrorBoundary><Component {...props} render={render} /> </ErrorBoundary>
                return <Component {...props} render={render} />
            }} />
        )
    }
}

export default withRouter(AuthRoute)